﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>字典明细管理</title>
    <#include "../common/link.ftl">
    <script>
        $(function () {
            //新增/编辑点击事件
            //点添加明细时, 需要先判断左边是否有选中字典目录,如果没有,提示"请先选中目录"
            $('.btn-input').click(function () {
                var value = ${qo.parentId};
                if (value < 0) {
                    $.messager.alert("警告", "请先选中数据!");
                    return;
                }


                $('#editForm input').val('');
                //事件源
                var json = $(this).data('json');
                if (json) {
                    //回显表单
                    $("input[name=id]").val(json.id);
                    $("input[name=title]").val(json.title);
                    $("input[name=sequence]").val(json.sequence);
                }

                $('input[name=parentName]').val($('#parent .active').html());//回显带有active样式的目录标题
                $('input[name=parentId]').val(value);//回显带有active样式的目录id

                //弹出框
                $('#inputModel').modal('show');
            })

            //保存点击事件
            $('.btn-submit').click(function () {
                $.post('/systemDictionaryItem/saveOrUpdate.do', $('#editForm').serialize(), function (data) {
                    if (data.success) {
                        $.messager.popup("成功")
                        window.setTimeout(function () {
                            window.location.reload();
                        }, 1000)
                    } else {
                        $.messager.popup(data.msg);
                    }
                });
            })



            //默认一打开页面,不需要查询字典明细,因为数据太多太乱，查出来也没有意义


            //若用户在新增或者编辑的时候，不填入序号，则后台自动设置当前明细的序号为同一分类下的最大序号+1的值
        })
    </script>
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
    <#include "../common/navbar.ftl">

    <!--菜单回显-->
    <#assign currentMenu="systemDictionaryItem"/>

    <#include "../common/menu.ftl">
    <div class="content-wrapper">
        <section class="content-header">
            <h1>字典明细管理</h1>
        </section>
        <section class="content">
            <div class="box">
                <div class="row" style="margin:20px">
                    <div class="col-xs-3">
                        <div class="panel panel-default">
                            <div class="panel-heading">字典目录</div>
                            <div class="panel-body">
                                <div class="list-group" id="parent">
                                    <#list systemDictionaries as dic>
                                        <a id="${dic.id}"
                                           href="/systemDictionaryItem/list.do?parentId=${dic.id}"
                                           class="list-group-item">${dic.title}</a>
                                    </#list>
                                </div>
                                <script>
                                    //目录中的选中高亮显示
                                    $('#${qo.parentId}').addClass('active');
                                </script>
                            </div>
                        </div>
                    </div>


                    <#--当你想测试是否 x > 0 或 x >= 0，编写 <#if x > 0> 和 <#if x >= 0> 是错误的，
                     因为第一个 > 会结束 #if 标签。
                     要这么来做，可以编写 <#if x gt 0> 或 <#if gte 0>。
                     也请注意，如果比较发生在括号内部，那么就没有这样的问题，
                     比如 <#if foo.bar(x > 0)> 就会得到想要的结果。-->
                    <div class="col-xs-9">
                    <#if qo.parentId gte 1>
                        <!--高级查询--->
                        <form class="form-inline" id="searchForm" action="/systemDictionaryItem/list.do" method="post">
                            <input type="hidden" name="currentPage" id="currentPage" value="1">
                            <input type="hidden" name="parentId" value="${qo.parentId}">

                            <a href="#" class="btn btn-success btn-input" style="margin: 10px">
                                <span class="glyphicon glyphicon-plus"></span> 添加
                            </a>
                        </form>
                        <!--编写内容-->
                        <div class="box-body table-responsive no-padding ">
                            <table class="table table-hover table-bordered">
                                <tr>
                                    <th>编号</th>
                                    <th>字典明细标题</th>
                                    <th>字典明细序号</th>
                                    <th>操作</th>
                                </tr>
                            <#list pageInfo.list as systemDictionaryItem>
                                <tr>
                                    <td>${systemDictionaryItem_index+1}</td>
                                    <td>${systemDictionaryItem.title}</td>
                                    <td>${systemDictionaryItem.sequence}</td>
                                    <td>
                                        <a href="#" data-json='${systemDictionaryItem.json}'
                                           class="btn btn-info btn-xs btn-input">
                                            <span class="glyphicon glyphicon-pencil"></span> 编辑
                                        </a>
                                    </td>
                                </tr>
                            </#list>
                            </table>
                            <#--分页-->
                            <#include "../common/page.ftl">
                        </div>
                    </#if>
                    </div>

                </div>
            </div>
        </section>
    </div>
    <#include "../common/footer.ftl">
</div>


<!-- 模态框 -->
<div class="modal fade" id="inputModel" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="myModalLabel">字典明细新增/编辑</h4>
            </div>

            <div class="modal-body">
                <form class="form-horizontal" action="/systemDictionaryItem/saveOrUpdate.do" method="post"
                      id="editForm">
                    <input type="hidden" name="id">
                    <!-- 用来提交到后台关联的 -->
                    <input type="hidden" name="parentId">

                    <div class="form-group" style="margin-top: 10px;">
                        <label for="parentName" class="col-sm-3 control-label">字典目录：</label>
                        <div class="col-sm-7">
                            <input type="text" class="form-control" name="parentName" readonly>
                        </div>
                    </div>

                    <div class="form-group" style="margin-top: 10px;">
                        <label for="title" class="col-sm-3 control-label">明细标题：</label>
                        <div class="col-sm-7">
                            <input type="text" class="form-control" name="title"
                                   placeholder="请输入字典明细标题">
                        </div>
                    </div>

                    <div class="form-group" style="margin-top: 10px;">
                        <label for="sequence" class="col-sm-3 control-label">明细序号：</label>
                        <div class="col-sm-7">
                            <input type="text" class="form-control" name="sequence"
                                   placeholder="请输入字典明细序号">
                        </div>
                    </div>

                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary  btn-submit">保存</button>
            </div>
        </div>
    </div>
</div>
</body>
</html>
